<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/3/5
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>首页</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webapp/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">运城北大青鸟</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    ${user.username}
                </a>
                <dl class="layui-nav-child">
                    <dd><a  onclick="test()" >修改密码</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/logout">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <sec:authorize access="hasRole('ADMIN')" >
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="javascript:;">系统管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/admin/intoUser')">用户管理</a></dd>
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/admin/intoJournal')">操作日志</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
                <sec:authorize access="hasAnyRole('SWEIR','ADMIN')">
                    <li class="layui-nav-item">
                        <a href="javascript:;">轮播图管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/swiper/intoSwiper')">查看轮播图</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
                <sec:authorize access="hasAnyRole('USER','ADMIN')">
                    <li class="layui-nav-item">
                        <a href="javascript:;">用户信息</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/student/intoStudent')">查看用户</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
                <sec:authorize access="hasAnyRole('SIGN','ADMIN')">
                    <li class="layui-nav-item">
                        <a href="javascript:;">活动图片</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/sign/intoSign')">查看活动</a></dd>
                            <dd><a href="javascript:;" onclick="loadHtml('${path}/sys/phone/intoPhone')">咨询电话</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
                <sec:authorize access="hasAnyRole('WORK','ADMIN')">
                    <li class="layui-nav-item">
                        <a href="javascript:;">就业学员</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;"onclick="loadHtml('${path}/sys/entry/intoEntry')">查看就业学员</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
                <sec:authorize access="hasAnyRole('CLASS','ADMIN')">
                    <li class="layui-nav-item">
                        <a href="javascript:;">课程信息</a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;"onclick="loadHtml('${path}/sys/classInfo/intoClassInfo')">课程管理</a></dd>
                        </dl>
                    </li>
                </sec:authorize>
            </ul>
        </div>
    </div>
    <audio src="${path}/webapp/music/msg.mp3" id="myaudio" controls="controls" loop="false" hidden="true"></audio>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;" id="content"><img src="${pageContext.request.contextPath}/webapp/images/b4.jpg"> </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>
<script src="${path}/webapp/layui.js"></script>
<script type="text/javascript" src="${path}/webapp/js/jquery-3.1.1.js"></script>
<script>

        layui.use(['element','layer'], function(){
            var element = layui.element;
            var layer = layui.layer;

        });


    function loadHtml(url) {
        $("#content") .load(url);

    }
    //修改密码弹出层
    function test() {
        //示范一个公告层
        layer.open({
            type: 1
            ,title: '密码修改' //不显示标题栏
            ,closeBtn: false
            ,area: '300px;'
            ,shade: 0.8
            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
            ,btn: ['提交', '退出']
            ,btnAlign: 'c'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' +
                '请输入旧密码<br/><input type="text" id="oldPassword"/><br/> ' +
                '请输入要修改的密码<br/><input type="password" id="password"/>' +
                '</div>'
            ,success: function(layero){
                var btn = layero.find('.layui-layer-btn');
                btn.find('.layui-layer-btn0').click(function () {
                    var oldPassword = layero.find("#oldPassword").val();
                    var password = layero.find("#password").val();
                    $.ajax({
                        url:'${pageContext.request.contextPath}/sys/user/updatePassword',
                        method:'post',
                        data:{'password':password,'oldPassword':oldPassword},
                        dataType:'json',
                        success:function (data) {
                            if(0==data){
                                layer.msg("原密码错误");
                            }else{
                                layer.msg("修改成功");
                            }
                        },
                        error:function () {
                            layer.msg("服务器忙，请稍后重试");
                        }
                    })
                })
            }
        });

    }

        var websocket=null;
        if('WebSocket' in  window){
            websocket=new WebSocket('ws://localhost:8080/WebSocketServer');
        }else{
            layer.msg('该浏览器不支持websocket',{icon:2,time:1000});
        }
        websocket.onopen=function(event){
            console.info('建立连接');
        }
        websocket.onclose=function(event){
            console.info('关闭连接');
        }
        websocket.onmessage=function(event){
            if(event.data!=null){
                document.getElementById('myaudio').play();
                layer.confirm("您有新的消息请注意查收！", {
                    btn: ['确定','取消']
                }, function(){
                    closePlay();

                },function(){
                    closePlay();
                });
            }
            //弹框提醒，播放音乐
        }
        websocket.onerror=function(){
            console.info('websocket通讯发生错误！');
        }
        websocket.onbeforeunload=function(){
            websocket.close();
        }

        function autoPlay() {
            var myAuto = document.getElementById('myaudio');
            myAuto.play();
        }
        function closePlay() {
            var myAuto = document.getElementById('myaudio');
            myAuto.pause();
            myAuto.load();
        }
</script>

</body>
</html>